package com.unieagle.exam.ui;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.unieagle.exam.R;
import com.unieagle.exam.app.ExamApplication;
import com.unieagle.exam.widget.BackButton;

public class BaseActivity extends Activity{
	
	protected TextView mTvTitle;
	
	protected TextView mTvRight;
	
	protected BackButton mBBBack;
	
	private ProgressDialog progressDialog;


	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
	}
	
	protected void init() {
		mTvTitle = (TextView)findViewById(R.id.title);
		mTvRight = (TextView)findViewById(R.id.right);
		mBBBack = (BackButton)findViewById(R.id.left);
		mBBBack.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				finish();
			}
		});
	}

	@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
		super.onDestroy();
	}

	@Override
	protected void onPause() {
		// TODO Auto-generated method stub
		super.onPause();
	}

	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		ExamApplication.instance.updateApp();
	}

	protected void immersedStyle() {
		getWindow().requestFeature(Window.FEATURE_NO_TITLE);
		if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
			Window window = getWindow();
			window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
//                    | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION
			);
			window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
//                    | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
					| View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
			window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
			window.setStatusBarColor(Color.TRANSPARENT);
//            window.setNavigationBarColor(Color.TRANSPARENT);
		}
	}

	protected boolean loginCheck(){
		boolean rel = ExamApplication.instance.getAccountMnager().isLogin();
		if(!rel){
			if(!(this instanceof LoginActivity)){
				startActivity(new Intent(this, LoginActivity.class));
				finish();
			}
		}
		return rel;
	}

	protected void showProgress(String text) {
		if(progressDialog != null) {
			return;
		}
		progressDialog = new ProgressDialog(this);
		progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
		progressDialog.setMessage(text);
		progressDialog.setCancelable(false);
		progressDialog.show();
	}

	protected void dismissProgress(){
		progressDialog.dismiss();
		progressDialog = null;
	}
}
